<?php
include_once 'module/controls.php';
include_once 'js/ckeditor/ckeditor.php';
include_once 'model/slider/process.php';
$slider = new slider();
$c = new controls();
$fillOne = $slider->FillOne($_GET);
?>
<div id="content">
    <div class="content_block">
        <h2 class="jquery_tab_title"><?php echo $phrase["manager_banner"] ?></h2>
        <form method="post" action="<?= $url["home"] ?>/menu/slider-process" enctype="multipart/form-data">
            <p>
                <?php echo $c->get_textHidden("id", $fillOne["banner_id"]) ?>
                <?php echo $c->get_label($phrase["banner_url"]) ?>
                <?php echo $c->get_textReadOnly("banner_url", $fillOne["banner_url"]) ?>
                <input class="button" type="button" value="Browser" onclick="BrowseServer();" />
                <span id="errorUrl" style="display: none">Url không được để trống.</span>
            </p>
            
            <p>
                <?php echo $c->get_label($phrase["lienket_link"]) ?>
                <?php $link = explode("http://", $fillOne["banner_link"]); ?>
                <?php echo $c->get_text("banner_link", $link[1]) ?>
                <span id="errorLink" style="display: none">Link không được để trống hoặc Định dạng Link sai.</span>
            </p>
            
            <p>
                <?php echo $c->get_label($phrase["slider_title"]) ?>
                <?php echo $c->get_textLager("slider_title", $fillOne["title"]) ?>
                <span id="errorTitle" style="display: none">Title không được để trống.</span>
            </p>

            <p>
                <?php echo $c->get_label($phrase["slider_description"]) ?>
                <?php echo $c->get_textarea("slider_description", $fillOne["description"]) ?>
            </p>
            <p>
                <?php echo $c->get_button("update", $phrase["update"]) ?>
            </p>
        </form>
    </div>
</div>
<script type="text/javascript">    
    function BrowseServer()
    {
        // You can use the "CKFinder" class to render CKFinder in a page:
        var finder = new CKFinder();
        finder.basePath = "<?= $url["home"] ?>/js/ckfinder/";	// The path for the installation of CKFinder (default = "/ckfinder/").
        finder.selectActionFunction = SetFileField;
        finder.popup();
    }

    // This is a sample function which is called when a file is selected in CKFinder.
    function SetFileField( fileUrl )
    {
        $('#banner_url').val(fileUrl);
    }
    
    $('#update').click(function(){
        var linkReg = /^([\w-\.]+([\w-]+\.)+[\w-]{2,4})?$/;
        var link = $('#banner_link').val();
        var url = $('#banner_url').val();
        var title = $('#slider_title').val();
        if(url == ""){
            $('#errorUrl').show();
            $('#errorLink').hide();
            $('#errorTitle').hide();
            return false;
        }
        if(title == ""){
            $('#errorTitle').show();
            $('#errorLink').hide();
            $('#errorUrl').hide();
            return false;
        }
        if(link == ""){
            $('#errorLink').show();
            $('#errorUrl').hide();
            $('#errorTitle').hide();
            return false;
        }
        if(!linkReg.test(link)){
            $('#errorLink').show();
            $('#errorUrl').hide();
            $('#errorTitle').hide();
            return false;
        }
    });
</script>